﻿using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.DependencyInjection;
using Serilog.Events;
using System.Windows.Media.Imaging;
using System;
using WatchDog;
using WatchDog.WatchItemManages;

namespace WatchDogApp.Windows
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow
    {
         
 
        public MainWindow()
        {
            InitializeComponent();
 
            this.comboBox1.Items.Add("生产模式");
            this.comboBox1.Items.Add("调试模式");
            this.comboBox1.SelectedItem = "生产模式";
            this.comboBox1.SelectionChanged += (s, e) =>
            {
                if (this.comboBox1.SelectedItem.ToString() == "调试模式")
                {
                    WatchDog.Serilog.loggingLevelSwitch.MinimumLevel = LogEventLevel.Debug;
                    WindowsServiceManage.ExecuteCommand(ZWatchDogServiceManage.serviceName, WindowsServiceCustomCommands.ServiceLogLevelDebug);
                }
                else
                {
                    WatchDog.Serilog.loggingLevelSwitch.MinimumLevel = LogEventLevel.Warning;
                    WindowsServiceManage.ExecuteCommand(ZWatchDogServiceManage.serviceName, WindowsServiceCustomCommands.ServiceLogLevelWarning);
                }
            };

            

            var _vm = App.Current.Service.GetRequiredService<MainWindowViewModel>();
      
            _vm.ServiceStatus = "状态：" + ZWatchDogServiceManage.GetStatus();
             

            this.IsVisibleChanged += (s, e) =>
            {
                if (this.IsVisible)
                    _vm.Start();
                else 
                    _vm.Stop();
            };   
            this.DataContext = _vm;

            //this.dataGrid.SelectionChanged += (s, e) =>
            //{
            //    if (e.AddedItems.Count == 1)
            //    {
            //        var item = e.AddedItems[0] as WatchItemDto;

            //        var see = item;
            //    }
            //    //var ss = s;
            //    //var ee = e;
            //};
        }

    }


}
